<?php 
	include_once 'config/common.php';
	
	//当前年份
	if($_GET['year']==false){
		$year = date("Y");
	}else{
		$year = $_GET['year'];
	}
	$smarty->assign("year",$year);
		
	//当前月份
	if($_GET['month']==false){
		$month = date("m");
	}else{
		$month = $_GET['month'];
	}
	$smarty->assign("month",$month);
	
	//上月
	if($month!='1'){
		$prev['month'] = str_pad($month-1, 2, 0, STR_PAD_LEFT);
		$prev['year'] = $year;
	}else{
		$prev['month'] = '12';
		$prev['year'] = $year-1;
	}
	$smarty->assign("prev",$prev);
	
	//下月
	if($month!='12'){
		$next['month'] = str_pad($month+1, 2, 0, STR_PAD_LEFT);
		$next['year'] = $year;
	}else{
		$next['month'] = '1';
		$next['year'] = $year+1;
	}
	$smarty->assign("next",$next);
	
	//当月1号转为时间戳
	$nowtime = mktime(0,0,0,$month,1,$year);
	//今天的时间戳
	$todaytime = strtotime(date("Y-m-d"));
	//今天
	$today = date('j');
	//当月天数
	$daysofmonth = date("t",mktime(0,0,0,$month,1,$year));
	//当月第一天是周几
	$weekofbeginday = date(w,$nowtime);
	//当月最后一天是周几
	$weekofendday = date(w,mktime(0,0,0,$month,$daysofmonth,$year));
	//上月天数
	$daysofprevmonth = date(t,mktime(0,0,0,$month-1,1,$year));
	
	$day_list = array();
	
	//上月后几天
	for($i = 1;$i<=$weekofbeginday-1;$i++){
		$day['day'] = $daysofprevmonth-($weekofbeginday-1)+$i;
		$day['color'] = "gray";
		$thistime = mktime(0,0,0,$prev['month'],$i,$prev['year']); 
		$thistime==$todaytime ? $day['background']="#CCC" : $day['background']="#fff";
		$thistime>$todaytime ? $day['edit'] = '1' : $day['edit'] = '0'; 
		$day_list[] = $day;
	}
	
	//本月
	for($i = 1;$i<=$daysofmonth;$i++){
		$day['day'] = $i;
		$day['color'] = 'black';
		$thistime = mktime(0,0,0,$month,$i,$year);
		$thistime==$todaytime ? $day['background']="#CCC" : $day['background']="#fff";
		$thistime>$todaytime ? $day['edit'] = '1' : $day['edit'] = '0';
		$day_list[] = $day;
	}
	
	//下月前几天
	for($i = 1;$i<=7-$weekofendday&&$weekofendday!=0;$i++){
		$day['day'] = $i;
		$day['color'] = "gray";
		$thistime = mktime(0,0,0,$next['month'],$i,$next['year']);
		$thistime==$todaytime ? $day['background']="#CCC" : $day['background']="#fff";
		$thistime>$todaytime ? $day['edit'] = '1' : $day['edit'] = '0';
		$day_list[] = $day;
	}
	
	$smarty->assign("day_list",$day_list);
	$smarty->display("date.html");
?>